package selectClass.web;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import selectClass.Ingredient;
import selectClass.Ingredient.Type;
import selectClass.Student;
import selectClass.Taco;
import selectClass.User;
import selectClass.data.IngredientRepository;
import selectClass.data.TacoRepository;
import selectClass.data.UserRepository;

import javax.validation.Valid;
import java.security.Principal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Controller
@Configuration
@Validated
@RequestMapping("/information")
public class informationController {
    private UserRepository userRepo;

    public informationController(
            UserRepository userRepo
    ){
        this.userRepo=userRepo;
    }
    @GetMapping
    public String studentInformation(Model model, @AuthenticationPrincipal User user, Principal principal,SessionStatus sessionStatus) {


        String username = principal.getName();
        user = userRepo.findByUsername(username);
        model.addAttribute("user", user);
        log.info(principal.getName());

        sessionStatus.setComplete();
        return "information";
    }
}
